/*
 * @Date: 2025-07-14 13:46:30
 * @LastEditors: Csir 2215995096@qq.com
 * @LastEditTime: 2025-08-08 13:23:41
 * @FilePath: \infomng-ui\vue.config.js
 */
/*
 * @Date: 2025-06-03 18:01:42
 * @LastEditors: Csir 2215995096@qq.com
 * @LastEditTime: 2025-06-04 10:18:15
 * @FilePath: \infomng-ui\vue.config.js
 */
/**
 * 配置参考:
 * https://cli.vuejs.org/zh/config/
 */
// const url = "http://localhost:58080";
const url = "http://183.129.138.242:18092";
//  const url = "http://infomng-gateway:9999";
// const url = "http://183.129.138.242:18092";
// const url = 'http://192.168.39.100:9999'
// const url = 'http://183.129.138.242:18078'
//const url = 'http://219.159.79.40:50007'
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = ["js", "css"];
module.exports = {
  publicPath: "/o3/",
  // 保存时是否保存 eslint 检查
  lintOnSave: false,
  productionSourceMap: false,
  chainWebpack: (config) => {
    const entry = config.entry("app");
    +entry.add("babel-polyfill").end();
    entry.add("classlist-polyfill").end();
  },
  css: {
    // 忽略 CSS order 顺序警告
    extract: { ignoreOrder: true },
  },
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === "production") {
      // 仅在生产环境下启用该配置
      return {
        performance: {
          // 打包后最大文件大小限制
          maxAssetSize: 1024000,
        },
        // plugins: [
        //   new CompressionWebpackPlugin({
        //     filename: "[path].gz[query]",
        //     // algorithm: "gzip",
        //     test: new RegExp(
        //       "\\.(" + productionGzipExtensions.join("|") + ")$"
        //     ),
        //     threshold: 1024, // 只有大小大于该值的资源会被处理,当前配置为对于超过1k的数据进行处理，不足1k的可能会越压缩越大
        //     minRatio: 0.99, // 只有压缩率小于这个值的资源才会被处理
        //     deleteOriginalAssets: true, // 删除原文件
        //   }),
        // ],
      };
    }
  },
  // 配置转发代理
  devServer: {
    disableHostCheck: true,
    port: 8095,
    proxy: {
      "/api": {
        target: url, // 目标服务器地址
        ws: true, // 是否启用 WebSocket
        changeOrigin: true, // 是否修改请求头中的 Origin 字段
        pathRewrite: {
          "^/api": "",
        },
      },
      "/": {
        target: url,
        ws: false, // 需要websocket 开启
        pathRewrite: {
          "^/": "/",
        },
      },
    },
  },
};
